$(function () {
    function xiaositongxue() {
        let sub = $('#ipt').val()
        str = `<li class="right_word">
        <img src="img/person02.png" /><span>${sub}</span></li>`
        $('#talk_list').append(str)
        $('#ipt').val('')
        resetui()
        // 会获取小思的回答
        $.ajax({
            type: 'get',
            url: 'http://www.liulongbin.top:3006/api/robot',
            data: {
                spoken: sub
            },
            success: function (res) {
                let text = res.data.info.text
                str = `<li class="left_word">
                <img src="img/person01.png" /> <span>${text}</span>
              </li>`
                $('#talk_list').append(str)
                // 将获取的数据转换为语音
                $.ajax({
                    type: 'get',
                    url: 'http://www.liulongbin.top:3006/api/synthesize',
                    data: {
                        text
                    },
                    success: function (res) {
                        $('#voice').attr('src', res.voiceUrl)
                    }
                })
                resetui()
            }

        })
    }
    $('#btnSend').click(function () {
        xiaositongxue()
    })
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            $("#btnSend").trigger("click");
        }
    });
})